package cn.fl.notice.service.impl;


import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.flow.controller.SysFlowRejRsnController;
import cn.fl.notice.api.ISysFlowNoticeService;
import cn.fl.notice.condition.SysFlowNoticeCfgQueryCondition;
import cn.fl.notice.transform.SysFlowNoticeCfgVOTransform;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.fl.notice.service.ISysFlowNoticeCfgService;
import cn.fl.notice.vo.SysFlowNoticeCfgVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;

import java.util.List;

/**
 * @Description: 流程待办消息通知配置 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class SysFlowNoticeCfgServiceImpl implements ISysFlowNoticeCfgService {

    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(SysFlowRejRsnController.class);

    @Autowired
    private ISysFlowNoticeService sysFlowNoticeService;


    @Override
    public Long add(SysFlowNoticeCfgVO entity) throws BaseException {
        if (null == entity) {
            BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
            return null;
        }
        return sysFlowNoticeService.addFlowNoticeCfg(SysFlowNoticeCfgVOTransform.toDTO(entity));
    }


    @Override
    public boolean modify(SysFlowNoticeCfgVO entity) throws BaseException {
        if (null == entity) {
            BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
            return false;
        }
        return sysFlowNoticeService.modifyFlowNoticeCfg(SysFlowNoticeCfgVOTransform.toDTO(entity));
    }


    @Override
    public SysFlowNoticeCfgVO getSysFlowNoticeCfg(Long userId, String sysCd) throws BaseException {
        if (StringUtils.isEmpty(userId)) {
            BaseLogUtils.info(logger, "getSysFlowNoticeCfg", "用户ID不能为空!", CurrentThreadContext.getCurrentUserName());
            throw new BaseException("用户ID不能为空!");
        }
        if (StringUtils.isBlank(sysCd)) {
            BaseLogUtils.info(logger, "getSysFlowNoticeCfg", "系统编码不能为空!", CurrentThreadContext.getCurrentUserName());
            throw new BaseException("系统编码不能为空!");
        }
        SysFlowNoticeCfgQueryCondition query = new SysFlowNoticeCfgQueryCondition();
        query.setSysCd(sysCd);
        query.setUsrId(userId);
        List<SysFlowNoticeCfgVO> list = SysFlowNoticeCfgVOTransform.toVOList(this.sysFlowNoticeService.getFlowNoticeCfg(query));
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }

}
